<?php

//传值, 把值复制一份传递给新的变量
$a = 123;
$b = $a;
$b = 456;
echo $a, "\t", $b, "\n";
$a = ['name' => '张三', 'age' => 22];
$b = $a;
$b['age'] = 18;
print_r($a);
print_r($b);
//传引用，可以认为是创建原来变量的一个别名
$a = 123;
$b =& $a; //$b就是$a的别名
$b = 567;
echo $a, "\t", $b, "\n";
$a = ['name' => '张三', 'age' => 22];
$b =& $a;
$b['name'] = '李四';
$b['age'] = 18;
print_r($a);
print_r($b);
//函数参数引用传递的例子
function f(string &$name)
{
    $name = $name . '丰'; // 拼接字符串
}

$xm = '张三';
f($xm);
echo $xm, "\n";

$a = [22, 11, 33, 88, 55];
sort($a);
print_r($a);


//局部变量就是函数内部定义的变量
function ff()
{
    $aaa = "Hello";
}

ff();
// echo $aaa,"\n";

//函数外边定义的变量叫全局变量, 函数中使用时必须声明为global
function f3()
{
    global $a;
    print_r($a);
}

f3();

//静态变量仅在局部函数中存在，但当程序执行离开此作用域时，其值并不丢失
function test()
{
    static $a = 0; //static表示为静态变量，函数结束时其值仍保留
    $a++;
    echo "第 $a 次调用函数\n";
}

test();
test();
//条件运算符，包含三个操作数
$a = 10;
echo $a > 100 ? 200 : 100, "\n"; //100
echo $a ?: 100, "\n"; //10
$a = 0;
echo $a ?: 100, "\n"; //100

//拼接字符串 .
echo 123 . 456, "\n"; //"123456"
$a = "Hello ";
$a .= "Zs"; // $a = $a . "Zs"; //复合赋值运算符
echo $a, "\n";

//数组解构
$info = ['张三', '男', '13624511868'];
list($name, $sex, $tel) = $info; // 列出所有变量
echo "$name 性别：{$sex}，电话：$tel\n";
[$name, $sex, $tel] = $info;
echo "$name 性别：{$sex}，电话：$tel\n";
$a = ["name" => "zhangsan", "age" => 22];
["age" => $age, "name" => $name] = $a;
echo "name=$name, age=$age\n";






